package tc.orcl.lab4;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Locale;

public class Task4
{

	public static void main(String[] args)
	{
		try
		{
			Class.forName("oracle.jdbc.driver.OracleDriver");
			System.out.println("JDBC driver is OK.");
		}
		catch (ClassNotFoundException e)
		{
			System.out.println("Error: JDBC driver is wrong!");
			System.out.println(e.getMessage());
			e.printStackTrace();
			System.exit(0);
		}
			
		Locale locale = Locale.getDefault();
		System.out.println("Default locale is " + locale);
		Locale.setDefault(Locale.ENGLISH);
			
		String url = new String("");
		url = "jdbc:oracle:thin:@localhost:1521:XE";
			
		String user = "vadik3";
		String password  = "oxe";
		
		try
		{
			Connection con = DriverManager.getConnection(url, user, password);
			System.out.println("Connection with URL " + url + " is OK.");
			
			Locale.setDefault(locale);
			
			try
			{
				Statement st = con.createStatement();
				con.setAutoCommit(false);
				
				for (int i = 0; i < 1000; i++)
				{
					String sql = String.format("DELETE FROM employees "
											+ "WHERE "
											+ "employee_id = %d",
											i+210);
					st.executeUpdate(sql);
				}
				System.out.println("DELETE is OK.");
				
				con.commit();
				st.close();
			}
			catch (SQLException e)
			{
				System.out.println("Error: DELETE is wrong!");
				System.out.println(e.getMessage());
			}
			
			con.close();
		}		
		catch (SQLException e)
		{
			System.out.println("Error: Connection is wrong!");
			e.printStackTrace();
		}
	}
	
}
